var x = 0, y = 1, z = 2,
	random = Math.random, round = Math.round;

function cross(U, V) {
    var crossP = [];

    crossP[x] = U[y]*V[z]-U[z]*V[y];
    crossP[y] = U[z]*V[x]-U[x]*V[z];
    crossP[z] = U[x]*V[y]-U[y]*V[x];

    return crossP;
}

function dot(U, V) {
   return U[x]*V[x] + U[y]*V[y] + U[z]*V[z];
}

function minus(U, V) {	// subtract U from V
   var vec = [];

   vec[x] = V[x]-U[x];
   vec[y] = V[y]-U[y];
   vec[z] = V[z]-U[z];

   return vec;
}

function det(a, b, c, d) {
   // (a-d).[(b-d)x(c-d)]
   
   console.log('w = ', minus(d, a)); 
   console.log('u = ', minus(d, b)); 
   console.log('v = ', minus(d, c)); 
   console.log('normal (u x v) = ', cross( minus(d,b), minus(d,c) ) );
   
   return dot( minus(d,a),  cross( minus(d,b), minus(d,c) ) );
}

var p1, q1, r1, p2, q2, r2, vCtr = -2, i, j, k,
	URL = 'http://www.bodurov.com/VectorVisualizer/?vectors=';
/*
for (i = -3; i < 3; i++) {
	for (j = -3; j < 3; j++) {
		for (k = -3; k < 3; k++) {
			vCtr++;
			if (vCtr < 0) p1 = [i, j, k];
			else if (vCtr == 0) q1 = [i, j, k];
			else {
				vCtr = -2;
				r1 = [i, j, k];
				URL = URL + printTriangleShape(p1, q1, r1);
			}
		};
	};
};
//print(URL);
*/

for (i = -10; i < 23; i+=4) {
	p1 = [round(random()*i), round(random()*i), round(random()*i)];
	q1 = [round(random()*i), round(random()*i), round(random()*i)];
	r1 = [round(random()*i), round(random()*i), round(random()*i)];
	p2 = [round(random()*i), round(random()*i), round(random()*i)];
	q2 = [round(random()*i), round(random()*i), round(random()*i)];
	r2 = [round(random()*i), round(random()*i), round(random()*i)];
	
	console.log( '[ q2, q1, p2, p1 ] = ',outputTestConfigURL(p1,q1,r1, p2,q2,r2, q2,q1,p2,p1) );
	console.log('[ q2, q1, p2, p1 ] = ', det(q2, q1, p2, p1) );
	console.log('[ p2, r1, r2, p1 ] = ', det(p2, r1, r2, p1) );
	readline();
};


/*
p1 = [0,0,6],	// P0
q1 = [-3,0,0],	// P1
r1 = [3,0,0],	// P2
p2 = [7,-3,-3],	// Q0  - p2 = [-4,-30,3] set p2 to the left of p1
q2 = [10,3,3],	// Q1
r2 = [4,3,3];	// Q2

console.log( '[ q2, q1, p2, p1 ] = ',outputTestConfigURL(p1,q1,r1, p2,q2,r2, q2,q1,p2,p1) );

console.log( '[ p2, r1, r2, p1 ] = ',outputTestConfigURL(p1,q1,r1, p2,q2,r2, p2,r1,r2,p1) );

console.log('[ q2, q1, p2, p1 ] = ', det(q2, q1, p2, p1) );
console.log('[ p2, r1, r2, p1 ] = ', det(p2, r1, r2, p1) );

console.log('d & v ---------------------------------');
console.log('[ p1, q1, p2, q2 ] = ', det(p1, q1, p2, q2) );
console.log('[ p1, r1, r2, p2 ] = ', det(p1, r1, r2, p2) );
*/
    
